package com.sgb.kjwl.view.ui.activity.self.carMaster;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.CountDownTimer;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.core.util.Pair;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.fondesa.recyclerviewdivider.DividerDecoration;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.sgb.alimaplibrary.util.ToastUtil;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityOfferDetailsBinding;
import com.sgb.kjwl.model.entity.OrderEntity;
import com.sgb.kjwl.model.entity.self.AddField;
import com.sgb.kjwl.model.entity.self.CarInfoListEntity;
import com.sgb.kjwl.model.entity.self.MyOfferDetailsEntity;
import com.sgb.kjwl.model.entity.transport.OfferGoodsSourcePlaceEntity;
import com.sgb.kjwl.model.entity.transport.SingleItemConstant;
import com.sgb.kjwl.model.entity.transport.SingleItemEntity;
import com.sgb.kjwl.utils.ActivityJump;
import com.sgb.kjwl.utils.DialogFunction;
import com.sgb.kjwl.utils.DialogHelper;
import com.sgb.kjwl.utils.NumberUtil;
import com.sgb.kjwl.view.ui.activity.transport.PayGeneralQuotationForCompanyActivity;
import com.sgb.kjwl.view.ui.adapter.transport.CarInfoAdapter;
import com.sgb.kjwl.view.ui.activity.transport.PayQuotationOrderForCompanyActivity;
import com.sgb.kjwl.view.ui.adapter.transport.CargoCustomValueAdapter;
import com.sgb.kjwl.view.ui.adapter.transport.OrderGoodsInfoAdapter;
import com.sgb.kjwl.view.widget.transport.InvoiceInfoBottomDialog;
import com.sgb.link.entity.merchant.PublishIndustryEntity;
import com.sgb.link.utils.EntityConversion;
import com.swgk.core.util.MLog;
import com.swgk.core.util.UserOperating;
import com.sgb.kjwl.view.constant.RouterKey;
import com.sgb.kjwl.view.ui.activity.self.userInfo.VerificationCodeLoginActivity;
import com.sgb.kjwl.view.ui.activity.transport.BiddingOrderDetailsActivity;
import com.sgb.kjwl.view.ui.activity.transport.CargoQuotationActivity;
import com.sgb.kjwl.view.ui.activity.transport.DepartureCertificateActivity;
import com.sgb.kjwl.view.ui.activity.transport.PayGeneralQuotationOrderActivity;
import com.sgb.kjwl.view.ui.activity.transport.PayQuotationOrderActivity;
import com.sgb.kjwl.view.ui.activity.transport.driver.goods.FreightPrjDetailActivity;
import com.sgb.kjwl.view.ui.activity.transport.driver.goods.GeneralPrjDetailActivity;
import com.sgb.kjwl.view.ui.activity.transport.owner.TransportOrderDetailOwnerActivity;
import com.sgb.link.view.widget.ExpandedTextView;
import com.sgb.kjwl.viewmodel.self.carMakers.MyOfferDetailsModel;
import com.swgk.core.dialog.RoundDialog;
import com.swgk.core.util.ClickUtils;
import com.swgk.core.util.DateUtils;
import com.im.immodel.IMUtils;
import com.swgk.core.util.SharedPreferenceUtil;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

/**
 * Describe:
 * Author:  yangLei
 * Date:    2021/4/7
 */
public class MyOfferDetailsActivity extends AppActivity {

    MyOfferDetailsModel viewModel;
    private ActivityOfferDetailsBinding binding;
    private String sourceNo;
    //报价no
    private String offerNo;

    private MyOfferDetailsEntity offerEntity;
    private boolean isGeneralGoods;
    //自定义字段列表
    private List<SingleItemEntity> mCustomList;
    private OrderGoodsInfoAdapter mCustomAdapter;
    private InvoiceInfoBottomDialog invoiceDialog;
    private BottomSheetDialog carInfoWindow;
    private Timer timer;

    RequestOptions options = new RequestOptions().placeholder(R.mipmap.icon_company_default)//图片加载出来前，显示的图片
            .fallback(R.mipmap.icon_company_default) //url为空的时候,显示的图片
            .error(R.mipmap.icon_company_default);//图片加载失败后，显示的图片

    RequestOptions personOptions = new RequestOptions().placeholder(R.mipmap.morentu_person)//图片加载出来前，显示的图片
            .fallback(R.mipmap.morentu_person) //url为空的时候,显示的图片
            .error(R.mipmap.morentu_person);//图片加载失败后，显示的图片

    RequestOptions teamOptions = new RequestOptions().placeholder(R.drawable.icon_team_default)//图片加载出来前，显示的图片
            .fallback(R.drawable.icon_team_default) //url为空的时候,显示的图片
            .error(R.drawable.icon_team_default);//图片加载失败后，显示的图片

    public static void start(Context context, String offerNo, boolean isGeneralGoods) {
        Intent intent = new Intent(context, MyOfferDetailsActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.putExtra(RouterKey.NO, offerNo);
        intent.putExtra("isGeneralGoods", isGeneralGoods);//是否普通货源的报价详情
        context.startActivity(intent);
    }

    @Override
    protected void initView() {
        offerNo = getIntent().getStringExtra(RouterKey.NO);
        isGeneralGoods = getIntent().getBooleanExtra("isGeneralGoods", false);
        viewModel = new ViewModelProvider(this).get(MyOfferDetailsModel.class);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_offer_details);
        binding.topBar.titleView.setText("报价详情");
        binding.topBar.titleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 17);
        binding.topBar.ivBack.setOnClickListener(v -> finish());
        binding.offerBar.setOnClickListener(this);
        binding.goodsInfoBar.setOnClickListener(this);
        binding.callPhoneTab.setOnClickListener(this);
        binding.billingInformationMore.setOnClickListener(this);
        binding.carrierVehicleMore.setOnClickListener(this);
        binding.newCallPhoneTab.setOnClickListener(this);
        binding.llExchangeTab.setOnClickListener(this);

        if (isGeneralGoods) {
            binding.clStatus.setVisibility(View.GONE);
            binding.clStatusGeneral.setVisibility(View.VISIBLE);
        } else {
            binding.clStatus.setVisibility(View.VISIBLE);
            binding.clStatusGeneral.setVisibility(View.GONE);
        }
        if (TextUtils.isEmpty(offerNo)) {
            finish();
        }
        viewModel.detailsLiveData.observe(this, myOfferDetailsEntity -> showData(myOfferDetailsEntity));

    }

    @Override
    protected void onResume() {
        super.onResume();
        if (!TextUtils.isEmpty(offerNo))
            viewModel.getOfferDetails(this, offerNo);
    }

    /**
     * 数据展示
     */
    public void showData(MyOfferDetailsEntity offerEntity) {
        if (offerEntity == null)
            return;
        this.offerEntity = offerEntity;
        binding.bottomBar.setVisibility( isGeneralGoods ? View.VISIBLE : View.GONE);
        binding.newBottomBar.setVisibility( isGeneralGoods ? View.GONE : View.VISIBLE);
        binding.carInfoOffer.setVisibility( isGeneralGoods&&UserOperating.getInstance().isPersonal()  ? View.VISIBLE : View.GONE);
        binding.carInfoHintOffer.setVisibility(isGeneralGoods &&UserOperating.getInstance().isPersonal()  ? View.VISIBLE : View.GONE);
            binding.bottomBar.setVisibility(isGeneralGoods?View.VISIBLE:View.GONE);
            binding.newBottomBar.setVisibility(isGeneralGoods?View.GONE:View.VISIBLE);
        //自定义字段列表
        mCustomList = new ArrayList<>();
        mCustomList = getCustomList(offerEntity);
        mCustomAdapter = new OrderGoodsInfoAdapter(mCustomList, false);
        binding.rvOfferField.setLayoutManager(new LinearLayoutManager(this));
        mCustomAdapter.bindToRecyclerView(binding.rvOfferField);
        if (!TextUtils.isEmpty(offerEntity.getSourceNo()))
            sourceNo = offerEntity.getSourceNo();
        if (!TextUtils.isEmpty(offerEntity.getNo()))
            offerNo = offerEntity.getNo();
        if (isGeneralGoods) {
            binding.rlQuotePeopleInfo.setVisibility(View.GONE);
        } else {
            binding.rlQuotePeopleInfo.setVisibility(View.VISIBLE);
        }

        if (offerEntity.getOfferType() == 3) {//个人
            binding.companyNameHint.setVisibility(View.GONE);
            binding.companyNameValue.setVisibility(View.GONE);
            binding.companyCodeHint.setVisibility(View.GONE);
            binding.companyCodeValue.setVisibility(View.GONE);
            binding.companyTypeHint.setVisibility(View.GONE);
            binding.companyTypeValue.setVisibility(View.GONE);
            binding.companyCapitalHint.setVisibility(View.GONE);
            binding.companyCapitalValue.setVisibility(View.GONE);
            binding.companyFoundTimeHint.setVisibility(View.GONE);
            binding.companyFoundTimeValue.setVisibility(View.GONE);
            binding.companyAddressHint.setVisibility(View.GONE);
            binding.companyAddressHint.setVisibility(View.GONE);

            binding.ivOfferItemLogo.setVisibility(View.GONE);
            binding.rivOfferLogo.setVisibility(View.VISIBLE);
            Glide.with(this).load(offerEntity.getHeadImage()).apply(personOptions).into(binding.rivOfferLogo);
            binding.companyName.setText(TextUtils.isEmpty(offerEntity.getName()) ? "/" : offerEntity.getName());
            binding.businessAddress.setText(TextUtils.isEmpty(offerEntity.getName()) ? "/" : offerEntity.getName());
            binding.businessAddressText.setText(TextUtils.isEmpty(offerEntity.getTelphone()) ? "" : offerEntity.getTelphone());
        } else if (offerEntity.getOfferType() == 1) {//企业
            binding.companyNameHint.setVisibility(View.VISIBLE);
            binding.companyNameValue.setVisibility(View.VISIBLE);
            binding.companyCodeHint.setVisibility(View.VISIBLE);
            binding.companyCodeValue.setVisibility(View.VISIBLE);
            binding.companyTypeHint.setVisibility(View.VISIBLE);
            binding.companyTypeValue.setVisibility(View.VISIBLE);
            binding.companyCapitalHint.setVisibility(View.VISIBLE);
            binding.companyCapitalValue.setVisibility(View.VISIBLE);
            binding.companyFoundTimeHint.setVisibility(View.VISIBLE);
            binding.companyFoundTimeValue.setVisibility(View.VISIBLE);
            binding.companyAddressHint.setVisibility(View.VISIBLE);
            binding.companyAddressValue.setVisibility(View.VISIBLE);

            binding.ivOfferItemLogo.setVisibility(View.VISIBLE);
            binding.rivOfferLogo.setVisibility(View.GONE);
            Glide.with(this).load(offerEntity.getHeadImage()).apply(options).into(binding.ivOfferItemLogo);

            binding.companyNameValue.setText(TextUtils.isEmpty(offerEntity.getCompanyName()) ? "/" : offerEntity.getCompanyName());
            binding.companyCodeValue.setText(TextUtils.isEmpty(offerEntity.getCreditCode()) ? "/" : offerEntity.getCreditCode());
            binding.companyTypeValue.setText(TextUtils.isEmpty(offerEntity.getCompanyType()) ? "/" : offerEntity.getCompanyType());
            binding.companyCapitalValue.setText(TextUtils.isEmpty(offerEntity.getRegisteredCapital()) ? "/" : offerEntity.getRegisteredCapital() + "元");
            try {
                binding.companyFoundTimeValue.setText(TextUtils.isEmpty(offerEntity.getEstablishmentDate()) ? "/" : DateUtils.timestampToDate(Long.parseLong(offerEntity.getEstablishmentDate())));
            } catch (NumberFormatException exception) {

            }
            binding.companyAddressValue.setText(TextUtils.isEmpty(offerEntity.getBusinessAddress()) ? "/" : offerEntity.getBusinessAddress());

            binding.companyName.setText(TextUtils.isEmpty(offerEntity.getCompanyName()) ? "/" : offerEntity.getCompanyName());
            binding.businessAddress.setText(TextUtils.isEmpty(offerEntity.getName()) ? "/" : offerEntity.getName());
            binding.businessAddressText.setText(TextUtils.isEmpty(offerEntity.getTelphone()) ? "" : offerEntity.getTelphone());
        } else if (offerEntity.getOfferType() == 2) {//团队
            binding.companyNameHint.setVisibility(View.VISIBLE);
            binding.companyNameValue.setVisibility(View.VISIBLE);
            binding.companyCodeHint.setVisibility(View.VISIBLE);
            binding.companyCodeValue.setVisibility(View.VISIBLE);
            binding.companyTypeHint.setVisibility(View.VISIBLE);
            binding.companyTypeValue.setVisibility(View.VISIBLE);
            binding.companyCapitalHint.setVisibility(View.VISIBLE);
            binding.companyCapitalValue.setVisibility(View.VISIBLE);
            binding.companyCapitalValue.setTextColor(getResources().getColor(R.color.color_tab_one));

            binding.companyNameHint.setText("团队名称");
            binding.companyCodeHint.setText("经营业务");
            binding.companyTypeHint.setText("团队人数");
            binding.companyCapitalHint.setText("经营地址");

            binding.companyFoundTimeHint.setVisibility(View.GONE);
            binding.companyFoundTimeValue.setVisibility(View.GONE);
            binding.companyAddressHint.setVisibility(View.GONE);
            binding.companyAddressValue.setVisibility(View.GONE);
            binding.ivOfferItemLogo.setVisibility(View.GONE);
            binding.rivOfferLogo.setVisibility(View.VISIBLE);
            Glide.with(this).load(offerEntity.getHeadImage()).apply(teamOptions).into(binding.rivOfferLogo);

            binding.companyNameValue.setText(TextUtils.isEmpty(offerEntity.getTeamName()) ? "/" : offerEntity.getTeamName());
            binding.companyCodeValue.setText(TextUtils.isEmpty(offerEntity.getBusinessType()) ? "/" : offerEntity.getBusinessType());
            binding.companyTypeValue.setText(TextUtils.isEmpty(offerEntity.getScale()) ? "/" : offerEntity.getScale() + "人");
            binding.companyCapitalValue.setText(TextUtils.isEmpty(offerEntity.getBusinessAddress()) ? "/" : offerEntity.getBusinessAddress());

            binding.companyName.setText(TextUtils.isEmpty(offerEntity.getTeamName()) ? "/" : offerEntity.getTeamName());
            binding.businessAddress.setText(TextUtils.isEmpty(offerEntity.getName()) ? "/" : offerEntity.getName());
            binding.businessAddressText.setText(TextUtils.isEmpty(offerEntity.getTelphone()) ? "" : offerEntity.getTelphone());
        }
        if (!TextUtils.isEmpty(offerEntity.getTelphone())) {
            binding.businessAddressText.setOnClickListener(view ->
                    DialogHelper.showDialog(this, "确认呼叫", offerEntity.getTelphone(), "确定", new DialogFunction() {
                        @Override
                        public void normalRoundDialog() {
                            ActivityJump.jumpToPhone(MyOfferDetailsActivity.this, offerEntity.getTelphone());
                        }
                    })
            );
        }

        //货源方
        if (offerEntity.getPlace() != null) {
            OfferGoodsSourcePlaceEntity placeEntity = offerEntity.getPlace();
            String offerPlace = "";
            String add_s = "";
            if (!TextUtils.isEmpty(placeEntity.getCityName())) {
                add_s += placeEntity.getCityName() + " ";
            }
            if (!TextUtils.isEmpty(placeEntity.getDistrictName())) {
                add_s += placeEntity.getDistrictName();
            }
            if (!TextUtils.isEmpty(add_s)) {
                offerPlace += add_s;
            }


            String add_e = "";
            if (!TextUtils.isEmpty(placeEntity.getDestCityName())) {
                add_e += placeEntity.getDestCityName() + " ";
            }
            if (!TextUtils.isEmpty(placeEntity.getDestDistrictName())) {
                add_e += placeEntity.getDestDistrictName();
            }
            if (!TextUtils.isEmpty(add_e)) {
                offerPlace += " → ";
                offerPlace += add_e;
            }
            binding.offerPlaceS.setText(offerPlace);

//            if (!TextUtils.isEmpty(placeEntity.getTotalDistance())) {
//                StringBuilder builder = new StringBuilder();
//                builder.append("运程：约").append(placeEntity.getTotalDistance()).append("km");
//                binding.tvTotalDiatance.setText(builder);
//            }
        }

        String goodsInfo = "";
        if (!TextUtils.isEmpty(offerEntity.getGoodsTypeName())) {
            goodsInfo += offerEntity.getGoodsTypeName();
        }
        if (!TextUtils.isEmpty(offerEntity.getSecondGoodsTypeName())) {
            goodsInfo += "/" + offerEntity.getSecondGoodsTypeName();
        }
        if (!TextUtils.isEmpty(offerEntity.getWeight())) {
            goodsInfo += " " + NumberUtil.trim0(offerEntity.getWeight()) + "吨";
        }
        if (!TextUtils.isEmpty(offerEntity.getVolume())) {
            goodsInfo += " " + NumberUtil.trim0(offerEntity.getVolume()) + "方";
        }
        binding.goodsTv.setText(TextUtils.isEmpty(goodsInfo) ? "/" : goodsInfo);


        if (!TextUtils.isEmpty(offerEntity.getShipmentTime()) && !TextUtils.isEmpty(offerEntity.getShipmentEndTime())) {
            binding.shipmentTime.setText(DateUtils.formatDate(offerEntity.getShipmentTime(), "yyyy/MM/dd")
                    + "-" + DateUtils.formatDate(offerEntity.getShipmentEndTime(), "yyyy/MM/dd"));
        } else {
            binding.shipmentTime.setText("/");
        }

        if (!TextUtils.isEmpty(offerEntity.getSourceMessagePrice())) {
            binding.infoAmount.setText(NumberUtil.trim0(offerEntity.getSourceMessagePrice()) + "元");
        } else {
            binding.infoAmount.setText("/");
        }
        if (!TextUtils.isEmpty(offerEntity.getMessagePrice())) {
//            binding.messagePrice.setText(NumberUtil.trim0(offerEntity.getMessagePrice()) + "元");
        } else {
//            binding.messagePrice.setText("/");
        }

        if (isGeneralGoods) {
            //信息费
            if (TextUtils.isEmpty(offerEntity.getMessagePrice()) || "0".equals(NumberUtil.trim0(offerEntity.getMessagePrice()))) {
                binding.freightUnitHint.setVisibility(View.GONE);
                binding.freightUnit.setVisibility(View.GONE);
            } else {
                binding.freightUnitHint.setVisibility(View.VISIBLE);
                binding.freightUnit.setVisibility(View.VISIBLE);
            }
            binding.freightUnitHint.setText("信息费");
            binding.freightUnit.setText(!TextUtils.isEmpty(offerEntity.getMessagePrice()) ? NumberUtil.trim0(offerEntity.getMessagePrice()) + "元" : "/");

            if (offerEntity.getFreightType() == null || offerEntity.getFreightType() == 0) {
                //运费总价
                if (!TextUtils.isEmpty(offerEntity.getSourceAllFreight())) {
                    binding.freight.setText(NumberUtil.trim0(offerEntity.getSourceAllFreight()) + "元");
                } else {
                    binding.freight.setText("/");
                }
            } else {
                binding.freight.setText("电议");
            }
        } else {
            String unitStr = "";
            if (!TextUtils.isEmpty(offerEntity.getSourceFreight())) {
                unitStr += NumberUtil.trim0(offerEntity.getSourceFreight());
                if (!TextUtils.isEmpty(offerEntity.getFreightUnitWorls()))
                    unitStr += offerEntity.getFreightUnitWorls();
            }
            binding.freightUnit.setText(TextUtils.isEmpty(unitStr) ? "/" : unitStr);

            //运费总价
            if (!TextUtils.isEmpty(offerEntity.getSourceAllFreight())) {
                binding.freight.setText(NumberUtil.trim0(offerEntity.getSourceAllFreight()) + "元");
            } else {
                binding.freight.setText("/");
            }
        }

        if (isGeneralGoods) {

                if (!TextUtils.isEmpty(offerEntity.getFreight())) {
                    String value = "0";
                    if (offerEntity.getQuotationFreightUnit() == 1) {
                        value = "1";
                    } else if (offerEntity.getQuotationFreightUnit() == 2) {
                        value = NumberUtil.trim0(offerEntity.getWeight());
                    } else if (offerEntity.getQuotationFreightUnit() == 3) {
                        value = NumberUtil.trim0(offerEntity.getVolume());
                    } else {
                        value = NumberUtil.trim0(offerEntity.getWeight());
                    }
                    binding.myOffer.setText("单价" + NumberUtil.trim0(offerEntity.getFreight()) + offerEntity.getQuoteFreightUnitWorls() + " x " + value);
                } else {
                    binding.myOffer.setText("/");
                }
        } else {
            if (!TextUtils.isEmpty(offerEntity.getFreight())) {
                binding.myOffer.setText(NumberUtil.trim0(offerEntity.getFreight()) + "元/吨");
            } else {
                binding.myOffer.setText("/");
            }
        }
        //报价状态：1已报价  2已同意  3报价未同意 4超时未支付
        switch (offerEntity.getOfferStatus()) {
            case "1"://已报价
                binding.offerStatus.setText("已报价");
                binding.offerStatus.setTextColor(getResources().getColor(R.color.color_5792FD));
                binding.handleBtn.setText(isGeneralGoods ?  "再次报价":"更新报价");
                binding.rightBtn.setText(isGeneralGoods ? "更新报价" : "再次报价");
                binding.handleBtn.setOnClickListener(v -> {
                    updateOffer();
                });
                binding.rightBtn.setOnClickListener(v -> {
                    updateOffer();
                });
                if (!isGeneralGoods) {
                    binding.newBottomBar.setVisibility( isGeneralGoods ? View.GONE : View.VISIBLE);
                    if (!TextUtils.isEmpty(offerEntity.getEndTime()) && Long.parseLong(offerEntity.getEndTime()) > System.currentTimeMillis()) {
                        binding.handleBtn.setClickable(true);
                        binding.handleBtn.getBackground().setAlpha(255);
                        binding.rightBtn.setClickable(true);
                        binding.rightBtn.getBackground().setAlpha(255);
                    } else {
                        binding.handleBtn.setClickable(false);
                        binding.handleBtn.getBackground().setAlpha(128);
                        binding.rightBtn.setClickable(false);
                        binding.rightBtn.getBackground().setAlpha(128);
                    }
                } else {
                    binding.bottomBar.setVisibility(isGeneralGoods ? View.VISIBLE : View.GONE);
                }

                binding.offerStatusGeneral.setText("已报价");
                binding.offerStatusGeneral.setTextColor(getResources().getColor(R.color.c_5792FD));
                binding.statusExplainGeneral.setText("待货主处理");
                break;

            case "2"://已同意
                binding.offerStatus.setText("报价已同意");
                binding.offerStatus.setTextColor(getResources().getColor(R.color.color_06C764));
                if (!isGeneralGoods) {
                    binding.newBottomBar.setVisibility( View.VISIBLE);
                    binding.handleBtn.setText("查看订单");
                    binding.rightBtn.setText("查看订单");
                    binding.handleBtn.setOnClickListener(v -> {
                        toOrderDetail(offerEntity.getOrderNo());
                    });
                    binding.rightBtn.setOnClickListener(v -> {
                        toOrderDetail(offerEntity.getOrderNo());
                    });
                } else {
                    if (!TextUtils.isEmpty(offerEntity.getOrderNo()) && UserOperating.getInstance().isCompany()) {
                        binding.handleBtn.setVisibility(View.GONE);
                        if (offerEntity != null && !TextUtils.isEmpty(offerEntity.getOrderPayTime()) && !"0".equals(offerEntity.getOrderPayTime())) {
                            CountDownTimer timer = new CountDownTimer(NumberUtil.convertToLong(offerEntity.getOrderPayTime()), 1000) {
                                @Override
                                public void onTick(long millisUntilFinished) {
                                    String str = String.format("%s%s", NumberUtil.trim0(offerEntity.getMessagePrice()) + "元信息费支付中，请联系财务至资金中心-待付订单完成支付。剩余支付时间 ", DateUtils.formatDate(millisUntilFinished, "mm分ss秒"));
                                    binding.statusExplainGeneral.setText(str);

                                }

                                @Override
                                public void onFinish() {
                                    binding.statusExplainGeneral.setText("待车主支付" + NumberUtil.trim0(offerEntity.getMessagePrice()) + "元信息费");
                                }
                            };
                            timer.start();
                        }
                    } else {
                        binding.statusExplainGeneral.setText("待车主支付" + NumberUtil.trim0(offerEntity.getMessagePrice()) + "元信息费");

                    }
                    binding.bottomBar.setVisibility( View.VISIBLE);
                    binding.handleBtn.setText("支付信息费");
                    binding.handleBtn.setOnClickListener(v -> {
                        toPayMessage();
                    });
                    binding.rightBtn.setText("支付信息费");
                    binding.rightBtn.setOnClickListener(v -> {
                        toPayMessage();
                    });
                }

                binding.offerStatusGeneral.setText("报价待支付");
                binding.offerStatusGeneral.setTextColor(getResources().getColor(R.color.FFC000));


                break;

            case "3"://未同意
                if (isGeneralGoods) {
                    binding.bottomBar.setVisibility( isGeneralGoods ? View.VISIBLE : View.GONE);
                    binding.offerStatusGeneral.setText("报价已支付");
                    binding.offerStatusGeneral.setTextColor(Color.parseColor("#06C764"));
                    binding.statusExplainGeneral.setText("车主已支付" + NumberUtil.trim0(offerEntity.getMessagePrice()) + "元信息费");
                    binding.handleBtn.setText("查看订单");
                    binding.handleBtn.setOnClickListener(v -> {
                        toTransportOrderDetail(offerEntity.getOrderNo());
                    });
                    binding.rightBtn.setText("查看订单");
                    binding.rightBtn.setOnClickListener(v -> {
                        toTransportOrderDetail(offerEntity.getOrderNo());
                    });
                    binding.llRightBtn.setVisibility(View.VISIBLE);
                } else {
                    binding.newBottomBar.setVisibility(isGeneralGoods ? View.GONE : View.VISIBLE);
                    binding.llRightBtn.setVisibility(View.GONE);
                    binding.offerStatus.setText("报价未同意");
                    binding.offerStatus.setTextColor(getResources().getColor(R.color.FF2928));
                }
                break;
            case "5":
                binding.llRightBtn.setVisibility(View.GONE);
                binding.handleBtn.setVisibility(View.GONE);
                binding.offerStatus.setText("报价未同意");
                binding.offerStatus.setTextColor(getResources().getColor(R.color.FF2928));
                binding.offerStatusGeneral.setText("报价已失效");
                binding.offerStatusGeneral.setTextColor(getResources().getColor(R.color.color_c0c4cc));
                String failueCause = "";
                switch (offerEntity.getFailureCause()) {
                    case 0:
                        if (UserOperating.getInstance().isPersonal()){
                            failueCause = "车主超时未支付信息费";
                        }else {
                            failueCause = "承运人超时未支付信息费";
                        }
                        break;
                    case 1:
                        failueCause = "货主未同意报价";
                        break;
                    case 2:
                        failueCause = "货主已下架货源";
                        break;
                    case 3:
                        failueCause = "货主已删除货源";
                        break;
                }
                binding.statusExplainGeneral.setText(failueCause);
                break;
            default:
                binding.llRightBtn.setVisibility(View.GONE);
                binding.offerStatus.setText("报价未同意");
                binding.offerStatus.setTextColor(getResources().getColor(R.color.FF2928));
                binding.bottomBar.setVisibility(isGeneralGoods ? View.VISIBLE : View.GONE);
                binding.newBottomBar.setVisibility( isGeneralGoods ? View.GONE : View.VISIBLE);
                break;
        }

        //报价方
        if (!TextUtils.isEmpty(offerEntity.getCreateTime())) {
            binding.offerTime.setText(DateUtils.formatDate(offerEntity.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
        } else {
            binding.offerTime.setText("/");
        }

        //车辆位置
        String address = "";
        if (!TextUtils.isEmpty(offerEntity.getDetailAddress())) {
            binding.carLocationHint.setText(isGeneralGoods == false ? "车辆位置" : UserOperating.getInstance().isPersonal()?"车辆位置":"位置");
            if ((offerEntity.getDetailAddress().contains("省") || offerEntity.getDetailAddress().contains("市"))) {
                binding.carLocation.setText(offerEntity.getDetailAddress());
            } else {
                binding.carLocation.setText(String.format("%s%s%s%s",
                        offerEntity.getProvinceName(),
                        offerEntity.getCityName(),
                        offerEntity.getDistrictName(),
                        offerEntity.getDetailAddress()));
            }
        } else {
            binding.carLocation.setText(TextUtils.isEmpty(address) ? "/" : address);
        }
        //联系信息
        String contactStr = "";
        if (!TextUtils.isEmpty(offerEntity.getContrcts()))
            contactStr += offerEntity.getContrcts();
        binding.contactInfo.setText(TextUtils.isEmpty(contactStr) ? "/" : contactStr);
        binding.contactInfoPhone.setText(TextUtils.isEmpty(offerEntity.getContrctsNumber()) ? "" : offerEntity.getContrctsNumber());

        //车辆信息
        String carInfo = "";
        if (offerEntity.getDriverAuths() != null && offerEntity.getDriverAuths().size() >= 1) {
            for (int i = 0; i < offerEntity.getDriverAuths().size(); i++) {
                carInfo += offerEntity.getDriverAuths().get(i).getCarNumber() + " ";
            }
        }
        binding.carInfo.setText(TextUtils.isEmpty(carInfo) ? "/" : carInfo);
        //车辆信息
        String carInfooffer = "";
        if (offerEntity.getDriverAuths() != null && offerEntity.getDriverAuths().size() >= 1) {
            if (!TextUtils.isEmpty(offerEntity.getDriverAuths().get(0).getCarNumber()))
                carInfooffer += offerEntity.getDriverAuths().get(0).getCarNumber() + " ";
            if (!TextUtils.isEmpty(offerEntity.getDriverAuths().get(0).getCarTypeName()))
                carInfooffer += offerEntity.getDriverAuths().get(0).getCarTypeName() + " ";
            if (!TextUtils.isEmpty(offerEntity.getDriverAuths().get(0).getCarLenName()))
                carInfooffer += offerEntity.getDriverAuths().get(0).getCarLenName() + " ";
        //栏高
        if (!TextUtils.isEmpty(offerEntity.getDriverAuths().get(0).getHeightHurdle()))
            carInfooffer += "栏高" + NumberUtil.trim0(offerEntity.getDriverAuths().get(0).getHeightHurdle()) + "米 ";
        //是否自卸
        if (!TextUtils.isEmpty(offerEntity.getIsDump())) {
            if (offerEntity.getIsDump().equals("1")) {
                carInfooffer += "自卸";
            } else {
                carInfooffer += "非自卸";
            }
        }
        }
        binding.carInfoOffer.setText(TextUtils.isEmpty(carInfooffer) ? "/" : carInfooffer);
        binding.carrierVehicleMore.setVisibility(TextUtils.isEmpty(carInfo) ?View.GONE:View.VISIBLE);
            binding.llCarrierVehicle.setVisibility(isGeneralGoods&&!UserOperating.getInstance().isPersonal()?View.VISIBLE:View.GONE);
            binding.llBillingInformation.setVisibility(View.VISIBLE);
        //报价次数大于1才显示历史报价入口
        if (offerEntity.getOfferNum() > 1) {
            binding.llOfferHistory.setVisibility(View.VISIBLE);
        } else {
            binding.llOfferHistory.setVisibility(View.GONE);
        }

        String inTime = DateUtils.timestampTo13DateNos(offerEntity.getInTime());
        if (TextUtils.isEmpty(inTime)&&isGeneralGoods){
            binding.arriveTime.setVisibility(View.GONE);
            binding.arriveTimeHint.setVisibility(View.GONE);
        }
        binding.arriveTime.setText(TextUtils.isEmpty(inTime) ? "/" : inTime);

        binding.scrollView.setVisibility(View.VISIBLE);
        //2.2.1新增
        binding.totalFreightText.setText(NumberUtil.trim0(offerEntity.getAllFreight())+"元");
        binding.totalFreightText.setVisibility(TextUtils.isEmpty(offerEntity.getFreight())?View.GONE:View.VISIBLE);
        binding.totalFreight.setVisibility(TextUtils.isEmpty(offerEntity.getFreight())?View.GONE:View.VISIBLE);
        binding.llBillingInformation.setVisibility(offerEntity.getInvoiceInfo()==null&&offerEntity.getPersonalInvoiceInfo()==null?View.GONE:View.VISIBLE);
        if (offerEntity.getPersonalInvoiceInfo()!=null){
            binding.billingInformationText.setText(offerEntity.getPersonalInvoiceInfo().getCompanyName());
        }
        if (offerEntity.getInvoiceInfo()!=null){
            binding.billingInformationText.setText(offerEntity.getInvoiceInfo().getCompanyName());
        }
        binding.llMarketingPublicity.setVisibility(TextUtils.isEmpty(offerEntity.getMarketingPublicity())?View.GONE:View.VISIBLE);
        binding.breachRl.setVisibility(TextUtils.isEmpty(offerEntity.getNote())?View.GONE:View.VISIBLE);
        binding.breachOfContractText.setText(offerEntity.getNote());
        binding.marketingPublicityMore.setText(offerEntity.getMarketingPublicity());
    }

    @Override
    public void onMultiClick(View v) {
        switch (v.getId()) {
            case R.id.offer_bar:
                //跳转历史报价
                if (!TextUtils.isEmpty(sourceNo))
                    HistoricalQuoteActivity.start(getActivity(), sourceNo, isGeneralGoods);
                break;

            case R.id.goods_info_bar:
                //跳转货源详情
                if (!TextUtils.isEmpty(sourceNo)) {
                    if (isGeneralGoods) {
                        GeneralPrjDetailActivity.start(getActivity(), sourceNo, 0, false);
                    } else
                        FreightPrjDetailActivity.start(getActivity(), sourceNo, false, false);
                }
                break;
            case R.id.annex_info://查看附件
                if (!ClickUtils.isDoubleClick2()) {
                    try {
                        List<String> images = new ArrayList<>();
                        String[] strings = offerEntity.getAccessory().split(",");
                        Collections.addAll(images, strings);
                        DepartureCertificateActivity.start(getActivity(), images, true);
                    } catch (Exception e) {

                    }
                }
                break;
            case R.id.call_phone_tab:
                if (isLogin()) {
                    if (offerEntity != null && !TextUtils.isEmpty(offerEntity.getGoodsOwnerIM())) {
//                        NimUIKit.startP2PSession(this, offerEntity.getGoodsOwnerIM());
                        IMUtils.getInstance().buildSingleTalking(offerEntity.getGoodsOwnerIM());
                    }
                } else {
                    //需要登陆
                    VerificationCodeLoginActivity.start(MyOfferDetailsActivity.this);
                }
                break;
            case R.id.carrier_vehicle_more:
                   if (offerEntity!=null && offerEntity.getDriverAuths()!=null){
                       initCarInfoWindow();
                   }
                break;
            case R.id.billing_information_more:
                if (offerEntity!=null){
                    if (invoiceDialog==null){
                        invoiceDialog = new InvoiceInfoBottomDialog(getActivity(), null);
                    }
                    invoiceDialog.show();
                    if (offerEntity.getInvoiceInfo()!=null){
                        InvoiceInfoBottomDialog.InvoiceInfo invoiceInfo= new InvoiceInfoBottomDialog.InvoiceInfo(offerEntity.getInvoiceInfo().getCompanyName(),offerEntity.getInvoiceInfo().getCreditCode(),offerEntity.getInvoiceInfo().getAddress(),offerEntity.getInvoiceInfo().getPhone(),offerEntity.getInvoiceInfo().getBank(),offerEntity.getInvoiceInfo().getBankAccount(),offerEntity.getInvoiceInfo().getBankNumber());
                        invoiceDialog.setInvoiceInfo(invoiceInfo);
                    }
                    if (offerEntity.getPersonalInvoiceInfo()!=null){
                        InvoiceInfoBottomDialog.InvoiceInfo invoiceInfo= new InvoiceInfoBottomDialog.InvoiceInfo(offerEntity.getPersonalInvoiceInfo().getCompanyName(),offerEntity.getPersonalInvoiceInfo().getNumber(),offerEntity.getPersonalInvoiceInfo().getAddress(),offerEntity.getPersonalInvoiceInfo().getTel(),offerEntity.getPersonalInvoiceInfo().getBank(),offerEntity.getPersonalInvoiceInfo().getBankAccount(),"");
                        invoiceDialog.setInvoiceInfo(invoiceInfo);
                    }
                }
                break;
            case R.id.ll_exchange_tab:
                if (isLogin()) {
                    if (offerEntity != null && !TextUtils.isEmpty(offerEntity.getGoodsOwnerIM())) {
//                        NimUIKit.startP2PSession(this, offerEntity.getGoodsOwnerIM());
                        IMUtils.getInstance().buildSingleTalking(offerEntity.getGoodsOwnerIM());
                    }
                } else {
                    //需要登陆
                    VerificationCodeLoginActivity.start(MyOfferDetailsActivity.this);
                }
                break;
            case R.id.new_call_phone_tab:
                if (!isLogin()) {
                    VerificationCodeLoginActivity.start(getActivity());
                    return;
                }
                if (offerEntity != null && !TextUtils.isEmpty(offerEntity.getGoodsOwnerPhone())) {
                    showCallDialog(offerEntity.getGoodsOwnerPhone());
                } else {
                    ToastUtil.show(getActivity(), "无联系方式");
                }
                break;

        }
    }
    private void initCarInfoWindow() {
        if (carInfoWindow == null) {
            carInfoWindow = new BottomSheetDialog(this);
            View view = LayoutInflater.from(this).inflate(R.layout.sheet_dialog_car_info, null);
            carInfoWindow.setContentView(view);
            carInfoWindow.setCancelable(true);
            carInfoWindow.setCanceledOnTouchOutside(true);

            RecyclerView rv = view.findViewById(R.id.rv_cars_info);
            rv.setLayoutManager(new LinearLayoutManager(this));
            CarInfoAdapter adapter = new CarInfoAdapter(offerEntity.getDriverAuths());
            rv.setAdapter(adapter);

            view.findViewById(R.id.close).setOnClickListener(v -> carInfoWindow.dismiss());
        }
        carInfoWindow.show();
    }
    private boolean isLogin() {
        return !TextUtils.isEmpty(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""));
    }

    /**
     * 打电话弹窗
     *
     * @param phone
     */
    public void showCallDialog(String phone) {
        new RoundDialog.Builder(this)
                .title("确认呼叫")
                .content(phone)
                .cancel("取消")
                .confirm("确定")
                .contentGravity(Gravity.CENTER)
                .cancelable(false)
                .confirmCallback(v -> callPhone(phone))
                .show();
    }

    /**
     * 更新报价
     */
    private void updateOffer() {
        if (!TextUtils.isEmpty(sourceNo))
            if (isGeneralGoods) {
                if (UserOperating.getInstance().isPersonal()) {
                    PayGeneralQuotationOrderActivity.startForResult(this,sourceNo, true, true, offerEntity.getFreight());
                } else {
                    PayGeneralQuotationForCompanyActivity.startForResult(this, sourceNo, true, true, offerEntity.getFreight());
                }
            } else {
                CargoQuotationActivity.startForResult(MyOfferDetailsActivity.this, sourceNo, true, UserOperating.getInstance().isPersonal() ? true : false, offerEntity.getFreight());
            }
    }

    /**
     * 支付信息费
     */
    private void checkPay() {
        //车辆状态校验
        viewModel.checkCarInfo(getActivity(), offerEntity);
    }

    /**
     * 查看竞价订单详情
     */
    private void toOrderDetail(String orderNo) {
//        Intent intent = new Intent(getActivity(), TransportOrderDetailOwnerActivity.class);
//        intent.putExtra("isGoodsOwner", 0);//这里是车主，传值：0
//        intent.putExtra("no", orderNo);//订单编号
//        startActivity(intent);
        BiddingOrderDetailsActivity.start(this, orderNo, 1);
    }

    /**
     * 查看货运订单详情
     */
    private void toTransportOrderDetail(String orderNo) {
        ActivityJump.jumpToActivity(this, TransportOrderDetailOwnerActivity.class, Pair.create("no", orderNo),
                Pair.create("isGoodsOwner", TransportOrderDetailOwnerActivity.CAR_OWNER));
    }


    /**
     * 查看竞价订单详情
     */
    private void toPayMessage() {
        //所有状态正常——>前去支付
        OrderEntity orderEntity = new OrderEntity();
        orderEntity.setGoodsSourceNo(offerEntity.getSourceNo());
        orderEntity.setCarNumber(offerEntity.getCarNumber());
        orderEntity.setHeightHurdle(offerEntity.getHeightHurdle());
        orderEntity.setWeight(offerEntity.getWeight());
        orderEntity.setCarLen(offerEntity.getCarLenName());
        orderEntity.setCarType(offerEntity.getCarTypeName());
        orderEntity.setCityName(offerEntity.getCityName());
        orderEntity.setProvinceName(offerEntity.getProvinceName());
        orderEntity.setDistrictName(offerEntity.getDistrictName());
        orderEntity.setDetailAddress(offerEntity.getDetailAddress());
        orderEntity.setCarImage(offerEntity.getCarImage());
        orderEntity.setDriverNo(offerEntity.getDriverNo());
        orderEntity.setCarOfferNo(offerEntity.getCarOfferNo());
        orderEntity.setGoodsOfferNo(offerEntity.getGoodsOfferNo());
        orderEntity.setNote(offerEntity.getNote());
        orderEntity.setDiyField(offerEntity.getDiyField());
        orderEntity.setQuotation(true);
        orderEntity.setIsDump(offerEntity.getIsDump());
        orderEntity.setAllFreight(offerEntity.getAllFreight());
        orderEntity.setInTime(offerEntity.getInTime());
        if (isGeneralGoods) {
            if (UserOperating.getInstance().isPersonal()) {
                PayQuotationOrderActivity.start(this, offerEntity.getGoodsOfferNo());
            } else {
                PayQuotationOrderForCompanyActivity.start(this, offerEntity.getGoodsOfferNo());
            }
        } else {
            PayQuotationOrderActivity.start(this, offerEntity.getGoodsOfferNo());
        }
    }

    /**
     * 为自定义字段添加布局
     *
     * @param content
     * @param entity
     */
    private void addCustomLayout(LinearLayout content, AddField entity) {
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.custom_field_layout_new, null);
        TextView remark_hint = view.findViewById(R.id.remark_hint);
        TextView content_tv = view.findViewById(R.id.content_tv);
        TextView expand_tv = view.findViewById(R.id.expand_tv);
        if (!TextUtils.isEmpty(entity.getKey())) {
            remark_hint.setText(entity.getKey());
        } else
            remark_hint.setText("自定义");

        content_tv.setText(entity.getValue());
        new ExpandedTextView().showTextPick(content_tv, expand_tv);
        content.addView(view);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == CargoQuotationActivity.REQUEST_CODE && resultCode == CargoQuotationActivity.RESULT_CODE) {
            if (data != null && !TextUtils.isEmpty(data.getStringExtra("no"))) {
                offerNo = data.getStringExtra("no");
            }
        }
    }
    private List<SingleItemEntity> getCustomList(MyOfferDetailsEntity mOrderEntity) {
        mCustomList.clear();
        if (mOrderEntity != null && mOrderEntity.getDiyField() != null && mOrderEntity.getDiyField().size() > 0) {
            for (int i = 0; i < mOrderEntity.getDiyField().size(); i++) {
                mCustomList.add(new SingleItemEntity(SingleItemConstant.TYPE_ONE,mOrderEntity.getDiyField().get(i).getKey(), mOrderEntity.getDiyField().get(i).getValue()));
            }
        }
        return mCustomList;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (timer==null)return;
        timer.cancel();
    }
}
